#include<bits/stdc++.h>
using namespace std;

//define n 15

long long n; // = 15;
long long a[200100]; // = {5,3,7,2,4,13,11,6,5,5,3,5,12,8,13};
long long arr[200100];
long long c[200100];
long long dis[200100];
int k;
int q;

long long loss(long long start,long long end){
	long long lossn = 0;
	for (int i=start;i<end;i++){
		if (dis[i]!=1){
			lossn+=c[i];
		}
		//if (i>start and c[i]>0 and dis[i]){
			
		//}
	}
	return lossn;
}

int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>q;
	for (int t = 0; t < q; t++)
	{
		cin>>n;
		//long long a[200100];
		//long long arr[200100];
		//long long c[200100];
		//long long dis[200100];
		k=0;
		//q=0;
		for (int s = 0;s<200000;s++){
			a[s]=0;
			arr[s]=0;
			c[s]=0;
			dis[s]=0;
		}
		
		for (int l = 0; l < n; l++)
		{
			cin>>a[l];
		}
		
		
		for (int i = 1; i < n; i++)
		{	
			long long mans = arr[i-1];
			long long pans;
			k = 0;
			//cout<<i<<"   ";
			for (int j = i-1; j >= 0; j--)
			{
				
				if (a[j] == a[i]){
					pans = arr[i-1] - loss(j+1,i) + a[i];
					if (pans>mans){
						mans = pans;
						k = i-j;
					}
					//cout<<loss(j+1,i)<<" ";
				}
			}
			//cout<<"   "<<k<<endl;
			
			if (k<=i and k!=0){
				dis[i] = k;
				c[i] = a[i];
			}
			arr[i] = mans;
		}
		
		//for (int i = 0; i < n; i++)
		//{
			//cout<<c[i]<<" ";
		//}
		//cout<<endl;
		//for (int i = 0; i < n; i++)
		//{
			//cout<<dis[i]<<" ";
		//}
		//cout<<endl;
		//for (int i = 0; i < n; i++)
		//{
			//cout<<arr[i]<<" ";
		//}
		cout<<arr[n-1]<<"\n";
	}
	
	return 0;
}
